---
hide_table_of_contents: true
---

import CodeBlock from "@theme/CodeBlock";

# Exa Search

Exa (formerly Metaphor Search) is a search engine fully designed for use by LLMs. Search for documents on the internet using natural language queries, then retrieve cleaned HTML content from desired documents.

Unlike keyword-based search (Google), Exa's neural search capabilities allow it to semantically understand queries and return relevant documents.
For example, we could search `"fascinating article about cats"` and compare the search results from Google and Exa.
Google gives us SEO-optimized listicles based on the keyword “fascinating”. Exa just works.

This notebook goes over how to use Exa Search with LangChain.

First, get an Exa API key and add it as an environment variable.
Get 1000 free searches/month by [signing up here.](https://dashboard.exa.ai/login)

## Usage

First, install the LangChain integration package for Exa:

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/exa @langchain/openai langchain
```

You'll need to set your API key as an environment variable.

The `Exa` class defaults to `EXASEARCH_API_KEY` when searching for your API key.

## Usage

import ToolExample from "@examples/tools/exa_search.ts";

<CodeBlock language="typescript">{ToolExample}</CodeBlock>

:::tip
You can see a LangSmith trace for this example [here](https://smith.langchain.com/public/775ea9a8-d54c-405c-9126-a012405d9099/r).
:::

## Using the Exa SDK as LangChain Agent Tools

We can create LangChain tools which use the [`ExaRetriever`](/docs/integrations/retrievers/exa) and the [`createRetrieverTool`](https://api.js.langchain.com/functions/langchain_tools_retriever.createRetrieverTool.html)
Using these tools we can construct a simple search agent that can answer questions about any topic.

import AgentExample from "@examples/tools/exa_agent.ts";

<CodeBlock language="typescript">{AgentExample}</CodeBlock>

```
{
  input: 'Summarize for me a fascinating article about cats.',
  output: 'The article discusses the research of biologist Jaroslav Flegr, who has been investigating the effects of a single-celled parasite called Toxoplasma gondii (T. gondii or Toxo), which is excreted by cats in their feces. Flegr began to suspect in the early 1990s that this parasite was subtly manipulating his personality, causing him to behave in strange, often self-destructive ways. He reasoned that if it was affecting him, it was probably doing the same to others.\n' +
    '\n' +
    "T. gondii is the microbe that causes toxoplasmosis, a disease that can be transmitted from a pregnant woman to her fetus, potentially resulting in severe brain damage or death. It's also a major threat to people with weakened immunity. However, healthy children and adults usually experience nothing worse than brief flu-like symptoms before quickly fighting off the protozoan, which then lies dormant inside brain cells.\n" +
    '\n' +
    "Flegr's research is unconventional and suggests that these tiny organisms carried by house cats could be creeping into our brains, causing everything from car wrecks to schizophrenia.\n" +
    '\n' +
    '(Source: [The Atlantic](https://www.theatlantic.com/magazine/archive/2012/03/how-your-cat-is-making-you-crazy/308873/))'
}
```

:::tip
You can see a LangSmith trace for this example [here](https://smith.langchain.com/public/d123ba5f-8535-4669-9e43-ac7ab3c6735e/r).
:::
